#!/usr/bin/perl
# Xlate.pl
use warnings;
use strict;

my ($langname,$filename, $marker, $mark, $value, $wholefile, $thisval, $template, %valueof);

print "Enter the language for the output html file: \n";
$langname = lc<>;   # get language name and turn it into lowecase
chomp $langname;

$filename = $langname . ".str";   # generate filename from language name
open(LANGFILE, "$filename");

#read in the markers & values in a hash
while(<LANGFILE>) {
   chomp($_);
   ($marker, $value) = split("\t", $_);
   $valueof{$marker} = $value;
}
close(LANGFILE);
# use the correct template
if ($langname =~ /arabic|hebrew/) {
$template = 'templateRight.html';
} else {$template = 'templateLeft.html'}

open(TMPLT,$template);
open(OUTFILE, ">$langname.html");

$wholefile=join('', <TMPLT>);   # slurp entire file into a string
 

close TMPLT;

foreach $mark (keys %valueof) {
   $thisval = $valueof{$mark};   # get the value related to the marker
   $wholefile =~ s/$mark/$thisval/g;   # do the replacement
}

print OUTFILE $wholefile;   # write out complete langname.html file
print "output written to $langname.html \n";
close OUTFILE;
